import Vue from 'vue'
import Vuex from 'vuex'
import router from '../router'
import http from '../request';
Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		token: http.getToken(),
	},
	mutations: {
		login(state, token) {
			state.token = token
			http.setToken(token.accessToken, token.refreshToken)
			router.push({path: '/'})
		},
		logout(state) {
			state.token = {}
			http.removeToken()
			router.replace({path: '/login'})
		},
	},
	actions: {
		//获取当前用户信息
		/*GetUserInfo({commit}) {
			return new Promise((resolve, reject) => {
				http.request({
					url: '/admin/info',
					success: (res) => {
						commit('setuserinfo', res.data) //更新状态
						resolve(res);
					},
					error: (err) => {
						reject(err);
					}
				})
			})
		},*/
	},
	getters: {
		isLoggedIn: state => !!state.token.accessToken
	  }
})